package com.fth.learn.chapter06;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 7.14的作业题
 * YiMi
 *
 * @author YiMi
 * @version 1.0
 * @date 2023/7/14 13:25
 */

public class work714 {
    public static void question01(){
        int[] array={1,9,2,5,4,8,3,6,7,10,8};
        System.out.println(Arrays.toString(array));
    }

    public static void question02(){
        int[] arr={1,9,2,5,4,8,3,6,7,10,8};

        Arrays.sort(arr);
        System.out.println("从小到大输出："+Arrays.toString(arr));

        int temp=0;
        for (int i = 0; i <arr.length ; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if (arr[j+1]>arr[j])
                {
                    temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        System.out.println("从大到小输出："+Arrays.toString(arr));

    }

    public static void question03(){
        int num=0;
        int a = 0;
        int[] arr={1,9,2,5,4,8,3,6,7,10,8};
        for (int i = 0; i < arr.length; i++) {
                if(a<arr[i]){
                    a = arr[i];
                    num = i;
                }
        }
        System.out.printf("数字%d是最大的，角标是%d\n",a,num);
    }

    public static void question04(){
        int[] arr = {72,89,65,58,87,91,53,82,71,93,76,68};
        int score = 0;
        double avg = 0;

        for (int i = 0; i < arr.length; i++) {
            score=arr[i]+score;
        }
        avg = (double) score/(arr.length+1);
//        System.out.println(avg);
        String str = String.format("%.2f", avg);
        System.out.println(str);
    }

    public static void question05(){
        int[] arr={20,45,78,34,16,3,99,56};
        int num=0;
        Arrays.sort(arr);
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]>50){
                num = i;
                break;
            }

        }
        int[] big = Arrays.copyOf(arr, num);
        System.out.println("大于50的有："+big.length+"个，数据是："+Arrays.toString(big));

        int[] small = new int[arr.length-num];
        System.arraycopy(arr,num,small,0,arr.length-num);
        System.out.println("小于50的有："+small.length+"个，数据是："+Arrays.toString(small));
    }

    //汉字题
//    打印出“三”字
    public static void question06(){
        for (int j = 0; j < 3; j++) {
            for (int i = 0; i < 10; i++) {
                System.out.printf("*");
            }
            System.out.println("\n");
        }
    }

//    打印出“十”字
    public static void question07(){
        for (int j = 0; j < 5; j++) {
            if(j==2){
                for (int k = 0; k < 5; k++) {
                    System.out.printf("*\t");
                }
                System.out.println();
            }else{
                for (int i = 0; i < 5; i++) {
                    if (i==2){
                        System.out.printf("*");
                    }else {
                        System.out.printf("\t");
                    }
                }
                System.out.println();
            }
        }
    }


//    打印出“田”字
    public static void question08(){
        for (int j = 0; j < 5; j++) {
            if(j==1||j==3){
                for (int k = 0; k < 5; k++) {
                    if(k==1||k==3){
                        System.out.printf("\t");
                    }else {
                        System.out.printf("*\t");
                    }
                }
                System.out.println();
            }else {
                for (int i = 0; i < 5; i++) {
                    System.out.printf("*\t");
                }
                System.out.println();
            }
        }
    }


//    打印出“中”字
    public static void question09(){
        //口
        for (int j = 0; j < 4; j++) {
            if(j==1||j==2){
                for (int k = 0; k < 6; k++) {
                    if(k==0||k==5){
                        System.out.printf("1\t");
                    }
                    else {
                        System.out.printf("\t");
                    }
                }
                System.out.println();
            }else {
                for (int i = 0; i < 6; i++) {
                    System.out.printf("0\t");
                }
                System.out.println();
            }
        }

    }


//    打印出“土”字



    //现有一个数组内容如下 ： {1,2,3,4,5,6,7} 请将数组里面所有的偶数索引的値，增加10,奇数的索引値增加5,打印出平均値。
    public static void question10(){
        int[] arr={1,2,3,4,5,6,7};
        double num=0;
        for (int i = 0; i < arr.length; i++) {
            if(i%2==0){
                arr[i]=arr[i]+10;
            }else {
                arr[i] = arr[i] +5;
            }
        }
        System.out.println(Arrays.toString(arr));
        for (int j = 0; j < arr.length; j++) {
            num=arr[j]+num;
        }
        System.out.println(num);
        num=(double)num/arr.length;
        System.out.println(num);
    }




        public static void main(String[] args) {
//            question01();
//            question02();
//            question03();
//            question04();
//            question05();
//            question06();
//            question07();
//            question08();
//            question09();
            question10();
        }

}
